//**********Elastic collison ****************
function Interaction_ElasticCollision(ParticleArray)
{

	var newVelocitiesX = new Array();
	var newVelocitiesY = new Array();
	
	for (var idx_ThisParticle = 0; idx_ThisParticle < ParticleArray.length; idx_ThisParticle++)
	{
		
		var thisParticle = ParticleArray[idx_ThisParticle];
		var newVelocityX = 0;
		var newVelocityY = 0;
		var allOtherMasses = 0;
		var allOtherSumOfDoubleMassVelocitiesX = 0;
		var allOtherSumOfDoubleMassVelocitiesY = 0;
		
		for (var i = 0; i < ParticleArray.length; i++)
		{
			var otherArticle = ParticleArray[i];
			//If other particle
			if (otherArticle != thisParticle)
			{
				allOtherMasses += otherArticle._mass;
				allOtherSumOfDoubleMassVelocitiesX += otherArticle._mass * otherArticle._velocityX;
				allOtherSumOfDoubleMassVelocitiesY += otherArticle._mass * otherArticle._velocityY;
			}
		}
		
		newVelocityX = thisParticle._velocityX * (thisParticle._mass - allOtherMasses) + allOtherSumOfDoubleMassVelocitiesX;
		newVelocityY = thisParticle._velocityY * (thisParticle._mass - allOtherMasses) + allOtherSumOfDoubleMassVelocitiesY;
		newVelocitiesX[idx_ThisParticle] = newVelocityX;
		newVelocitiesY[idx_ThisParticle] = newVelocityY;
	}
	
	for (var i = 0; i < ParticleArray.length; i++)
	{
		var particle = ParticleArray[i];
		particle._velocityX = newVelocitiesX[i];
		particle._velocityY = newVelocitiesY[i];
	}
	
	
}

//*******************************************